package com.fht.controller.food;


import com.fht.entity.FoodSpecification;
import com.fht.entity.FoodTasteCategory;
import com.fht.entity.MerchantsInformation;
import com.fht.from.FoodCategoryFrom;
import com.fht.service.food.FoodSpecificationService;
import com.fht.service.food.MerchantsInformationService;
import com.fht.util.ResultVOUtil;
import com.fht.vo.LayUITableVO;
import com.fht.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Slf4j
@RequestMapping("/food/specification")
public class foodSpecificationController {


    @Autowired
    public FoodSpecificationService foodSpecificationService;

    @Autowired
    public MerchantsInformationService merchantsInformationService;
    //菜品类别展示
    @GetMapping("/index")
    public String index(Model model){

        List<MerchantsInformation> merchantsInformationList = merchantsInformationService.findAllIdAndName();
        model.addAttribute("merchantsInformationList",merchantsInformationList);

        return "food/foodSpecification/index";

    }

    //获取菜品类别信息
    @GetMapping("/list")
    @ResponseBody
    public LayUITableVO<List<FoodSpecification>> list (@RequestParam(defaultValue = "1") Integer page,
                                                       @RequestParam(defaultValue = "10") Integer limit,
                                                       FoodCategoryFrom from){
        Map<String ,Object> map = new HashMap<>();
        map.put("page",page);
        map.put("limit",limit);
        map.put("from",from);

        LayUITableVO<List<FoodSpecification>> foodRecordList = foodSpecificationService.findPage(map);


        return foodRecordList;
    }

    //修改页面
    @GetMapping("/edit-ui")
    public String editUI(String recordId,Model model){
        model.addAttribute("recordId",recordId);
        return "food/foodSpecification/edit";

    }

    //修改页面（查询数据）
    @GetMapping("/sList")
    @ResponseBody
    public LayUITableVO<List<FoodSpecification>> tasetList (@RequestParam(defaultValue = "1") Integer page,
                                                            @RequestParam(defaultValue = "10") Integer limit,
                                                            String recordId){

        LayUITableVO<List<FoodSpecification>> vo = foodSpecificationService.selectByRecordId(recordId);


        return vo;
    }


    //执行修改
    @PostMapping("/add")
    @ResponseBody
    public ResultVO add(FoodSpecification foodSpecification){

        foodSpecificationService.add(foodSpecification);

        return ResultVOUtil.ok();
    }


    //执行删除
    @PostMapping("/del")
    @ResponseBody
    public ResultVO del(String id){
        foodSpecificationService.delelteById(id);
        return ResultVOUtil.ok();
    }


    //执行修改
    @PostMapping("/editAddPrice")
    @ResponseBody
    public ResultVO editAddPrice(FoodSpecification foodSpecification){

        foodSpecificationService.update(foodSpecification);

        return ResultVOUtil.ok();
    }


}
